//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;

namespace OpenLS.Chart.UI
{
    internal class ValueProvider
    {
        internal static IEnumerable<NumericValue> GetNumericValues(double min, double max, double step)
        {
            if (step == 0)
                yield break;
            int i = 0;
            foreach (double d in GetDoubleValues(min, max, step))
                yield return new NumericValue(null, i++, d);
        }
        internal static IEnumerable<double> GetDoubleValues(double min, double max, double step)
        {
            int returnedCount = 0;
            for (double d = min; d <= max; d += step)
            {
                if (Math.Abs(d) < step * 0.0000000000001)
                    yield return 0;
                else
                    yield return d;
                if (returnedCount++ > 1000)
                    break;
            }
        }

    }

    sealed class MinMaxToValuesConverter: IMultiValueConverter
    {
        #region IMultiValueConverter Members

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var result = new List<NumericValue>(ValueProvider.GetNumericValues((double)values[0], (double)values[1], (double)values[2]));
            return result;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion
       
    }
}
